Skip to content

librustc: emit loop for expr_repeat instead of 2n instructions in [x, n] #5524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 26, 2013

Conversation

luqmana
Copy link
Member

@luqmana luqmana commented Mar 24, 2013

let v = [24, ..1000]; now more or less emits the same IR as:

let mut i = 0;
while i < 1000 {
    v[i] = 24;
    i += 1;
}

LLVM will still turn it into a memset if possible with optimization on.

@huonw
Copy link
Member

huonw commented Mar 24, 2013

Sorry for all the criticism, but you did steal what I was trying to do. ;) (Though you did it far better than me.)

I've got a branch with the changes I suggested: https://github.com/dbaupp/rust/commit/6d50851bd005a942a70a052c4cd7327d8ab4b749.

(Also, something I struggled with: do you know if it is safe to drop the cleanups? I have no idea what their purpose is.)

@luqmana
Copy link
Member Author

luqmana commented Mar 24, 2013

@dbaupp Haha, thanks for the suggestions. I just applied the commit from your branch.

Regarding the cleanups, it seems to work fine as it but I did try a few things which didn't work out. It'd be good if someone more knowledge on the subject could comment. (@pcwalton ?)

@pcwalton
Copy link
Contributor

I'd like to see a test that tests something like let x = [ ~"hi", ..5 ], to make sure the cleanups happen right.

Regarding whether the temp cleanups are needed, I think they're needed in the case in which failure happens during a copy. I think that, due to the fact that copy constructors are not overridable in Rust, this can only happen due to OOM (which probably causes all sorts of bad things to happen in Rust anyway). So I think it's probably OK to omit them, but it should be noted with a comment.

bors added a commit that referenced this pull request Mar 26, 2013
`let v = [24, ..1000];` now more or less emits the same IR as:

```Rust
let mut i = 0;
while i < 1000 {
    v[i] = 24;
    i += 1;
}
```

LLVM will still turn it into a memset if possible with optimization on.
@bors bors closed this Mar 26, 2013
@bors bors merged commit e7f42f1 into rust-lang:incoming Mar 26, 2013
oli-obk pushed a commit to oli-obk/rust that referenced this pull request May 2, 2020
map_clone: avoid suggesting `copied()` for &mut

changelog: map_clone: avoid suggesting `copied()` for &mut

Fixes rust-lang#5524
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants